﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using WebComTest.WebUI.Models.RequestManagers;

namespace WebComTest.WebUI.Models
{
    public class TestData
    {
        [Key]
        public int Id { get; set; }

        public int ProjectEnvironmentId { get; set; }
        public virtual AppEnvironment ProjectEnvironment { get; set; }

        public string JsonMessage { get; set; }
        public string JsonMessageFormatted
        {
            get
            {
                return JsonHelper.FormatJson(this.JsonMessage);
            }
        }

        public int TestCaseId { get; set; }
        public virtual TestCase TestCase { get; set; }

        public string ExecLocally()
        {
            return Execute(TestCase.UseCase.App.LocalUrl);
        }
        public string ExecRemote()
        {
            return Execute(ProjectEnvironment.Url);
        }

        private string Execute(string url)
        {
            return new JsonRequest(url).Exec(this.JsonMessage);
        }
    }
}